package com.anzia.study_3;

import com.anzia.study_3.connections.MyRemote;
import com.anzia.study_3.utils.UIUtils;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.rpc.IRemoteObject;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class RemoteServiceAbility extends Ability {
	private static final HiLogLabel LABEL_LOG = new HiLogLabel(HiLog.LOG_APP, 0xD001002, "RemoteServiceAbility");

	// 实现
	private MyRemote remote = new MyRemote();

	@Override
	public void onStart(Intent intent) {
		HiLog.info(LABEL_LOG, "========RemoteServiceAbility::onStart");
		super.onStart(intent);
	}

	@Override
	public void onBackground() {
		super.onBackground();
		HiLog.info(LABEL_LOG, "========RemoteServiceAbility::onBackground");
	}

	@Override
	public void onStop() {
		super.onStop();
		HiLog.info(LABEL_LOG, "========RemoteServiceAbility::onStop");
	}

	// 每被调用一次，都会执行一次如下代码，可以用于计数
	@Override
	public void onCommand(Intent intent, boolean restart, int startId) {
		UIUtils.showTip(this, "远程onCommand," + restart + "," + startId);
	}

	@Override
	public IRemoteObject onConnect(Intent intent) {
		return remote;
	}

	// 这才是正常的断开
	@Override
	public void onDisconnect(Intent intent) {
		UIUtils.showTip(this, "链接断开了");
	}
}